// DataFile.h: This is the interface for the CDataFile class.
//
//////////////////////////////////////////////////////////////////////
//
//  This class is designed to provide a fast and simple interface
//  to access data from text-delimited files.
//
//  Version info: 
//		v1.0 - Initial Release
//		
//		v1.1 - Defined error codes
//			 - Provided const methods
//		     - used std::vector for private CNamedVariable* member
//
//		v1.2 - Added write capability
//			 - Added CreateVariable(), SetData(), and other methods.
//			 - Added statistical analysis.
//
//////////////////////////////////////////////////////////////////////
//
//	References:
//
//		Median Algorithm - 
//			Author: Wirth, Niklaus
//			Title: Algorithms + data structures = programs
//			Publisher: Englewood Cliffs: Prentice-Hall, 1976
//			Physical description: 366 p.
//			Series: Prentice-Hall Series in Automatic Computation
//			Notes - 
//					1. This code in public domain.
//					2. The origional code has been modified to 
//					   provide the best implementation for this class.
//
//
//		Press, W.H; Teukolsky, S.A.; Vetterling, W.T.; Flannery, B.P.
//			2002, Numerical Recipies in C++ Second Edition,
//			Cambridge University Press
//
//////////////////////////////////////////////////////////////////////
//
//	This class was written by Walter Storm (Nitron) and was developed
//	for the public domain. Use of this class is not restricted in any
//	way whatsoever.
//
//	Special thanks to all the members at The Code Project! 
//	(www.codeproject.com)
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_DATAFILE__INCLUDED_)
#define AFX_DATAFILE__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

namespace parsers
{

// These definitions are for buffer sizes
// and maximum line size for the file.
#if !defined(CDATAFILE_LIMITS)
#define CDATAFILE_LIMITS
	// max chars in a field		
	#define MAX_FIELD_BUFFER	1024
	// max chars in 1 line
	#define MAX_LINE_BUFFER		0x000FFFFF
#endif // !defined(CDATAFILE_LIMITS)

// This is the CDataFile class.
// Comments for the functions are in the implementation file.
class CDataFile  
{
public:
	typedef std::vector<float> Vector;
	typedef std::pair< CString, Vector > NamedVector;
	typedef std::vector< NamedVector > NamedVectorContainer; 

	CDataFile();
	virtual ~CDataFile();
	
	bool	ReadDataFile(LPCTSTR szFilePath, 
						 TCHAR szDelimiter = ',');

	const NamedVectorContainer& GetData() const	{	return m_nvVariables;};

	LPCTSTR GetFilePath() const;

	void ToString(CString& str, LPCTSTR szEOL = _T("\r\n"));

private:
	bool	SetFilePathAndDelimiterTo(LPCTSTR szFilePath, TCHAR chDelimiter);
	bool	mf_FileExists(LPCTSTR lpszFilePath);
	
	NamedVectorContainer m_nvVariables;
	TCHAR	m_chDelimiter;
	CString m_szFilePath;
	bool	m_bOKtoRead;
};

};

#endif // !defined(AFX_DATAFILE__INCLUDED_)
